Skip to content

make test_eager_matches_sdpa_inference less flaky - #34512

Merged
ydshieh merged 13 commits into
mainfrom
less_flaky
Oct 31, 2024
Merged

ydshieh merged 13 commits into
mainfrom
less_flaky

Conversation

@ydshieh

@ydshieh ydshieh commented Oct 30, 2024 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

With torch.bfloat16 the numerical difference/instability occurs quite often, especially with multiple hidden layers.

This PR first changes test_eager_matches_sdpa_inference to create models with only 1 hidden layer.

number of failures per 500 runs

main n_layer=1
llama 16 2
idefics2 391 15

Then it relaxes the condition a bit: only checks 80% of the sequences. If the results match on those 80%, the test pass.

This makes the test much less flaky. On 500 runs, it pass (for llama, mistral, idefics2 and Llava)

Finally, change the image size of llava and VipLlava from 30 to 8 so the sequence length is much smaller and avoid numerical issues.

Comment thread tests/test_modeling_common.py Resolved
Comment thread tests/test_modeling_common.py Resolved
Comment thread tests/test_modeling_common.py Resolved
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@gante gante left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you for fixing

Extra note: L4170 (model_sdpa = model_class.from_pretrained(tmpdirname, torch_dtype=torch_dtype)) should also have attn_implementation="sdpa", in case we update the default.

Comment thread tests/generation/test_utils.py Resolved
Comment thread tests/test_modeling_common.py Resolved
Comment thread tests/test_modeling_common.py Resolved

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

if model.get_output_embeddings() is None:
self.skipTest("DoLa is not supported for models that don't have output embeddings")

logits_processor_kwargs = self._get_logits_processor_kwargs(do_sample=True, config=model.config)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do sample is random no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the same value as in generation_kwargs = {...} a few line below.

Yes it is random but this method is test_...._sample so makes sense.

@ydshieh
ydshieh merged commit 114dd81 into main Oct 31, 2024
@ydshieh
ydshieh deleted the less_flaky branch October 31, 2024 17:34
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* try

* try

* try

* try

* try

* try

* update

* update

* update

* update

* update

* update

* update

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants